package Classes.GameDatas// ActionScript file
{
	import Classes.CustomEvents.ViewDataChangedEvent;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MMT_Character;
	
	public class GD_Character extends GameData
	{
		private var _controlEnabled:Boolean;/*可控标记*/
		private var _view:MMT_Character;/*显示对象*/
		private var _job:int;/*职业(擅长的领域)*/
		private var _suitsObj:Object;/*装束*/
		private var _lv:int;/*等级*/
		private var _life:int;/*生命*/
		private var _lifeMax:int=5;/*最大生命*/
		private var _currentOwnWeapon:String; //当前武器
		private var _characterId:Number;//角色ID
		public var gd_characterPlay:GD_Player;//角色GD
		private var _playSpeed:int=100;//人物速度
		
		private var _characterState:uint;/*角色状态  0 玩家在家操作 ；1 玩家雇用好友，雇佣好友在家操作；2.玩家在好友家操作；3.回放好友在我家操作*/
		
		public function GD_Character(job:int):void
		{
			this._job=job;
			this.init();
		}
		
		private function init():void
		{
			this._suitsObj=new Object;
		}
		
		public static function creat(creatObj:Object):GD_Character
		{
			var returnCharacter:GD_Character=new GD_Character(creatObj.job);
			returnCharacter._life=creatObj.life;
			return returnCharacter;
		}
		
		public function finishCure():void
		{
			this.life=this.lifeMax;
		}
		
		/*getter & setter*/
		public function get job():int
		{
			return _job;
		}
		
		public function get suitsObj():Object
		{
			return _suitsObj;
		}
		
		public function get lv():int
		{
			return _lv;
		}
		
		override public function release():void
		{
			super.release();
			if(this._view)
			{
				this._view.release();
				this._view=null;
			}
		}
		
		public function set lv(value:int):void
		{
			if(_lv!=value)
			{
				_lv = value;
				this.view.dispatchEvent(new ViewDataChangedEvent(ViewDataChangedEvent.DATACHANGED,"lv"));
			}
		}
		
		public function get life():int
		{
			return _life;
		}
		
		public function set life(value:int):void
		{
			if(value<_life){
				
				var sex:String=this.gd_characterPlay.playerSex;
				if(sex=="0")
					GU_Sound.instance.playCommSound("Body_Girl_BeHitted");
				else 
					GU_Sound.instance.playCommSound("Body_Boy_BeHitted");
			}
			_life = value;
			this.touchObserve("life");
		}
		
		public function get view():MMT_Character
		{
			if(!this._view)this._view=new MMT_Character(this);
			return _view;
		}
		
		/**
		 * 判断 是否可以控制该角色
		 * @return 
		 */		
		public function get controlEnabled():Boolean
		{
			return _controlEnabled;
		}
		
		public function set controlEnabled(value:Boolean):void
		{
			_controlEnabled = value;
		}
		
		public function get lifeMax():int
		{
			return _lifeMax
		}
		
		public function set lifeMax(value:int):void
		{
			_lifeMax = value;
			this.touchObserve("life");
		}
		
		/**
		 * 当前拥有的武器(拿在手上的) 
		 */
		public function get currentOwnWeapon():String
		{
			return _currentOwnWeapon;
		}
		
		/**
		 * @private
		 */
		public function set currentOwnWeapon(value:String):void
		{
			_currentOwnWeapon = value;
			this.touchObserve("weaponchange");
		}
		
		/**
		 * 角色ID 
		 * @return 
		 */		
		public function get characterId():Number
		{
			return _characterId;
		}
		
		public function set characterId(value:Number):void
		{
			_characterId = value;
		}
		
		
		/**
		 * 角色行动力 暂时专门用于好友 
		 * @param value
		 */		
		public function set actPoint(value:int):void
		{
			this.touchObserve("friendAct");
		}
		
		/**
		 * 角色状态  0 玩家在家操作 ；1 玩家雇用好友，雇佣好友在家操作；2.玩家在好友家操作；3.回放好友在我家操作 
		 */
		public function get characterState():uint
		{
			return _characterState;
		}
		
		/**
		 * @private
		 */
		public function set characterState(value:uint):void
		{
			_characterState = value;
		}
		
		public function set job(value:int):void
		{
			_job = value;
		}

		/**
		 * 人物速度   本人
		 */
		public function get playSpeed():int
		{
			var cs:int=_playSpeed;
			if(_playSpeed==0)cs=100;//防止后台没有返回玩家速度
			return cs;
		}

		/**
		 * @private
		 */
		public function set playSpeed(value:int):void
		{
			_playSpeed = value;
			this.touchObserve("palySpeed");
		}
		
		
	}
}